import org.w3c.dom.Node;

import server.ClientState;
import server.IProtocolHandler;
import xml.Message;
import dd.server.TestServerTurnResponse;
import dd.server.addChoiceResponseController;
import dd.server.addEdgeResponseController;
import dd.server.createResponseController;
import dd.server.signInResponseController;

/**
 * Sample implementation of a protocol handler to respond to messages received from clients.
 * You should follow this template when designing YOUR protocol handler.
 * <p>
 * To avoid issues with multiple clients submitting requests concurrently,
 * simply make the {@link #process(ClientState, Message)} method synchronized.
 * This will ensure that no more than one server thread executes this method
 * at a time.
 * <p>
 * Also extended to support detection of client disconnects so these can release the lock
 * if indeed the client was the one locking the model.
 */
public class SampleProtocolHandler implements IProtocolHandler  {
	
	public synchronized Message process (ClientState st, Message request) {
		Node child = request.contents.getFirstChild();
		String type = child.getLocalName();
		
	

		// send back our model
		if (type.equals ("signInRequest")) {
			//System.out.println(request);	
			return new signInResponseController().process(st, request);
		}
		else if(type.equals("createRequest")){
			return new createResponseController().process(st, request);
		}
		else if(type.equals("addChoiceRequest")){
			return new addChoiceResponseController().process(st, request);
		}
		else if(type.equals("addEdgeRequest")){
			//TestServerTurnResponse tstr = new TestServerTurnResponse(st,request);
			//tstr.setVisible(true);
			return new addEdgeResponseController().process(st, request);
		}
		// unknown? no idea what to do
		System.err.println("Unable to handle message:" + request);
		return null;
	}
}

	


